package sn.gandal.mobile.kalpet.android.guichet;

import com.sun.jersey.api.json.JSONJAXBContext;
import sn.gandal.mobile.kalpet.android.guichet.response.AccountResponse;

import javax.ws.rs.ext.ContextResolver;
import javax.xml.bind.JAXBContext;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: SOWDIOMYERO
 * Date: 29 sept. 2012
 * Time: 06:41:44
 * Version : ${VERSION}
 * To change this template use File | Settings | File Templates.
 */
//@Provider
public class JAXBContextResolver  implements ContextResolver<JAXBContext> {

	private JAXBContext context;
	private Class[] types = {AuthResponse.class, AccountResponse.class};

	public JAXBContextResolver() throws Exception {
		Map<String,Object> props = new HashMap<String,Object>();
		props.put(JSONJAXBContext.JSON_NOTATION, JSONJAXBContext.JSONNotation.MAPPED);
		props.put( JSONJAXBContext.JSON_ROOT_UNWRAPPING, Boolean.TRUE);
		this.context = new JSONJAXBContext(types, props);
	}

	public JAXBContext getContext(Class objectType) {
		return (types[0].equals(objectType)) ? context : null;
	}
}